package common.dateutils;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Component
public class AsyncFlowDateUtil {

    /**
     * 预设默认的时间格式
     */
    public static String getDefaultFormat() {
        //精确到时分秒的完整时间（英文） eg:2010-11-11 12:12:12
        return "yyyy-MM-dd HH:mm:ss";
    }


    //region 糊涂工具扩展

    /**
     * 获取时间
     *
     * @param localDateTime
     * @return
     */
    public static String htFormat(LocalDateTime localDateTime) {
        return LocalDateTimeUtil.format(localDateTime, DatePattern.NORM_DATETIME_PATTERN);
    }

    public static String htFormatyyyyMMdd(LocalDateTime localDateTime) {
        return LocalDateTimeUtil.format(localDateTime, DatePattern.NORM_DATE_PATTERN);
    }
    /**
     * 获取时间yyyy-MM-dd HH:mm:ss.SSS
     *
     * @param localDateTime 时间
     * @return yyyy-MM-dd HH:mm:ss.SSS
     */
    public static String htFormat_yyyyMMddHH_mm_ss_SSS(LocalDateTime localDateTime) {
        return LocalDateTimeUtil.format(localDateTime, DatePattern.NORM_DATETIME_MS_PATTERN);
    }
    public static String htFormatyyyyMMddHHmm(LocalDateTime localDateTime) {
        return LocalDateTimeUtil.format(localDateTime, DatePattern.NORM_DATETIME_MINUTE_PATTERN);
    }

    public static String htFormatyyyyMMddHHmmV2(LocalDateTime localDateTime) {
        return LocalDateTimeUtil.format(localDateTime, DatePattern.PURE_DATETIME_PATTERN);
    }
    public static String htFormatyyyyMMddHHmmV3(LocalDateTime localDateTime) {
        return LocalDateTimeUtil.format(localDateTime, DatePattern.ISO8601_PATTERN);

    }
    public static String htFormatHHmmss(LocalDateTime localDateTime) {
        return LocalDateTimeUtil.format(localDateTime, DatePattern.NORM_TIME_PATTERN);

    }

    public static String htFormatHHmm(LocalDateTime localDateTime) {
        String HHmmss = LocalDateTimeUtil.format(localDateTime, DatePattern.NORM_TIME_PATTERN);
        return HHmmss.substring(0, 5);
    }

    public static LocalDateTime htParse(String localDateTimeStr) {
        if (localDateTimeStr.contains("T")) {
            return LocalDateTimeUtil.parse(localDateTimeStr);
        } else {
            DateTimeFormatter df = DateTimeFormatter.ofPattern(getDefaultFormat());
            return LocalDateTime.parse(localDateTimeStr, df);
        }

    }

    //endregion


}



